package com.retail.bbq.cola.controller;

import com.retail.bbq.cola.service.ColaAnswerRecordService;
import com.retail.bbq.cola.service.ColaQuestionBankService;
import com.retail.bbq.cola.vo.ResultVO;
import com.retail.bbq.cola.vo.request.ColeQuestionRequest;
import com.retail.bbq.cola.vo.request.QuestionAnswerRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/question")
@Slf4j
public class ColaQuestionController {

    @Resource
    private ColaQuestionBankService colaQuestionBankService;

    @Resource
    private ColaAnswerRecordService colaAnswerRecordService;

    /**
     * 查询考题详情
     *
     * @param request
     * @return
     */
    @PostMapping("/detail")
    public ResultVO<?> queryQuestionDetailWithUserInfo(@RequestBody ColeQuestionRequest request) {
        return ResultVO.succ(colaQuestionBankService.queryQuestionDetailWithUserInfo(request));
    }

    /**
     * 保存考题结果
     *
     * @param answer
     * @return
     */
    @PostMapping("/answer")
    public ResultVO<?> answer(@RequestBody QuestionAnswerRequest answer) {
        return ResultVO.succ(colaAnswerRecordService.answerQuestion(answer));
    }

    /**
     * 查询考题答题历史
     *
     * @param answer
     * @return
     */
    @PostMapping("/answerHistory")
    public ResultVO<?> answerHistory(@RequestBody QuestionAnswerRequest answer) {
        return ResultVO.succ(colaAnswerRecordService.answerHistory(answer));
    }
}
